<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns="http://www.w3.org/1999/html">
<head>
	<th:block th:include="include :: header('自定义视图分页')" />
</head>
<body class="gray-bg">
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-page-size="10" 
				       data-show-custom-view="true" data-custom-view="customViewFormatter"
                       data-show-custom-view-button="true">
                </table>
			</div>
		</div>
	</div>

     <div class="col-sm-12 search-collapse">
         <form id="user-form">
             <input type="hidden" id="deptId" name="deptId">
             <input type="hidden" id="parentId" name="parentId">
             <div class="select-list">
                 <ul>
                     <li>
                         登录名称：<input type="text" name="loginName"/>
                     </li>
                     <li>
                         手机号码：<input type="text" name="phonenumber"/>
                     </li>
                     <li>
                         <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                         <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                     </li>
                 </ul>
             </div>
         </form>
     </div>
	
    <template id="profileTemplate">
        <div class="col-sm-4">
            <div class="contact-box">
                <a href="profile.html">
                    <div class="col-sm-4">
                        <div class="text-center">
                            <img alt="image" class="img-circle m-t-xs img-responsive" src="%IMAGE%">
                            <div class="m-t-xs font-bold">姓名：%userName%</div>
                        </div>
                    </div>
                    <div class="col-sm-8">
                        <h3><strong>部门：%dept.deptName%</strong></h3>
                        <br>
                        <p>邮箱：%email%</p>
                        <br>
                        <p>电话：%phonenumber%</p>
                    </div>
                    <div class="clearfix"></div>
                 </a>
             </div>
        </div>
    </template>

    <div th:include="include :: footer"></div>
    <th:block th:include="include :: bootstrap-table-custom-view-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/user";
        var datas = [[${@dict.getType('sys_normal_disable')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
		        showSearch: false,
		        showRefresh: false,
		        showToggle: false,
		        showColumns: false,
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'userId', 
					title : '用户ID'
				},
                    {
                        field: 'loginName',
                        title: '登录名称',
                        sortable: true
                    },
                    {
                        field: 'userName',
                        title: '用户名称'
                    },
                    {
                        field: 'dept.deptName',
                        title: '部门'
                    },
                    {
                        field: 'email',
                        title: '邮箱',
                        visible: false
                    },
                    {
                        field: 'phonenumber',
                        title: '手机'
                    },
				// {
				// 	field : 'userCode',
				// 	title : '用户编号'
				// },
				// {
				// 	field : 'userName',
				// 	title : '用户姓名'
				// },
				// {
				// 	field : 'userPhone',
				// 	title : '用户手机'
				// },
				// {
				// 	field : 'userEmail',
				// 	title : '用户邮箱'
				// },
				// {
				//     field : 'userBalance',
				//     title : '用户余额'
				// },
				{
                    field: 'status',
                    title: '用户状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                    	return $.table.selectDictLabel(datas, value);
                    }
                }]
            };
            $.table.init(options);
        });
        
        function customViewFormatter (data) {
            var template = $('#profileTemplate').html()
            var view = ''
            $.each(data, function (i, row) {
              view += template.replace('%userCode%', row.userCode)
                .replace('%IMAGE%', "http://demo.ruoyi.vip/img/profile.jpg")
                .replace('%userName%', row.userName)
                .replace('%email%', row.email)
                .replace('%phonenumber%', row.phonenumber)
                .replace('%dept.deptName%', row.dept.deptName);
            })

            return `<div class="row mx-0">${view}</div>`
        }

        /* 自定义重置-表单重置/隐藏框/树节点选择色/搜索 */
        function resetPre() {
            resetDate();
            $("#user-form")[0].reset();
            $("#deptId").val("");
            $("#parentId").val("");
            $(".curSelectedNode").removeClass("curSelectedNode");
            $.table.search();
        }
    </script>
</body>
</html>